package com.soul.server.controller;

import com.soul.model.vo.UserInfoVo;
import com.soul.server.server.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @author mdoya
 * @version 1.0
 * @description: 登录控制层
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class LoginController {

    @Autowired
    private UserService userService;

    /**
     *  登录 获取手机验证码
     * @param params
     * @return
     */
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public ResponseEntity login(@RequestBody Map<String,String> params){
        String phone = params.get("phone");
        log.info("获取验证码手机号码:{}",phone);
        userService.sendCode(phone);
        return ResponseEntity.ok(null);
    }

    /**
     *     用户登录(自动注册、老用户登录)
     * @param params 参数
     * @return
     */
    @PostMapping("/loginVerification")
    public ResponseEntity loginVerification(@RequestBody Map<String,String> params){
        String phone = params.get("phone"); // 手机号码
        String verificationCode = params.get("verificationCode"); // 手机验证码
        Map map = userService.login(phone,verificationCode);
        return ResponseEntity.ok(map);
    }

    /**
     *  首次登录---完善资料
     * @param userInfoVo 接受对象
     * @return
     */
    @PostMapping("/loginReginfo")
    public ResponseEntity loginReginfo(@RequestBody UserInfoVo userInfoVo){
        userService.loginReginfo(userInfoVo);
        return ResponseEntity.ok(null);
    }

    /**
     *  首次登录---补充头像
     * @param headPhoto
     * @return
     */
    @PostMapping("/loginReginfo/header")
    public ResponseEntity loginReginfoHeader(MultipartFile headPhoto){
        userService.loginReginfoHeader(headPhoto);
        return ResponseEntity.ok(null);
    }
}
